package edu.qqcui.study.config;

import java.io.IOException;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

/**
 * TODO
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021-06-26 11:20
 **/
public class MyTypeFilter implements TypeFilter {

	/**
	 * Determine whether this filter matches for the class described by
	 * the given metadata.
	 *
	 * @param metadataReader        the metadata reader for the target class
	 * @param metadataReaderFactory a factory for obtaining metadata readers
	 *                              for other classes (such as superclasses and interfaces)
	 * @return whether this filter matches
	 * @throws IOException in case of I/O failure when reading metadata
	 */
	@Override
	public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
		// 当前类的注解信息
		AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
		// 当前类的类信息
		ClassMetadata classMetadata = metadataReader.getClassMetadata();
		// 当前类的资源信息，包路径等
		Resource resource = metadataReader.getResource();
		String className = classMetadata.getClassName();
		System.out.println("------> " + className);
		// 新增自己的判断规则
		if (className.contains("er")) {
			return true;
		}
		return false;
	}
}
